package com.ruoyi.web.controller.official;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.official.domain.OfficialMessage;
import com.ruoyi.official.service.IOfficialMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线留言Controller
 * 
 * @author yuanqiji
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/official/message")
public class OfficialMessageController extends BaseController
{
    @Autowired
    private IOfficialMessageService officialMessageService;

    /**
     * 查询在线留言列表
     */
    @PreAuthorize("@ss.hasPermi('official:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(OfficialMessage officialMessage)
    {
        startPage();
        List<OfficialMessage> list = officialMessageService.selectOfficialMessageList(officialMessage);
        return getDataTable(list);
    }

    /**
     * 导出在线留言列表
     */
    @PreAuthorize("@ss.hasPermi('official:message:export')")
    @Log(title = "在线留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OfficialMessage officialMessage)
    {
        List<OfficialMessage> list = officialMessageService.selectOfficialMessageList(officialMessage);
        ExcelUtil<OfficialMessage> util = new ExcelUtil<OfficialMessage>(OfficialMessage.class);
        util.exportExcel(response, list, "在线留言数据");
    }

    /**
     * 获取在线留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('official:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(officialMessageService.selectOfficialMessageById(id));
    }

    /**
     * 新增在线留言
     */
    @PreAuthorize("@ss.hasPermi('official:message:add')")
    @Log(title = "在线留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficialMessage officialMessage)
    {
        return toAjax(officialMessageService.insertOfficialMessage(officialMessage));
    }

    /**
     * 修改在线留言
     */
    @PreAuthorize("@ss.hasPermi('official:message:edit')")
    @Log(title = "在线留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficialMessage officialMessage)
    {
        return toAjax(officialMessageService.updateOfficialMessage(officialMessage));
    }

    /**
     * 删除在线留言
     */
    @PreAuthorize("@ss.hasPermi('official:message:remove')")
    @Log(title = "在线留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(officialMessageService.deleteOfficialMessageByIds(ids));
    }
}
